<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	protected function _initDb() {
		$dbOption = $this->getOption ( 'resources' );
		$dbOption = $dbOption ['db'];
		// set up database
		$db = Zend_Db::factory ( $dbOption ['adapter'], $dbOption ['params'] );
		
		$db->setFetchMode ( Zend_Db::FETCH_ASSOC );
		$db->query ( "SET NAMES 'utf8'" );
		$db->query ( "SET CHARACTER SET 'utf8'" );
		
		Zend_Registry::set ( "connectDB", $db );
		
		// Khi thiáº¿t láº­p cháº¿ Ä‘á»™ nÃ y model má»›i
		// cÃ³ thá»ƒ sá»­ dá»¥ng Ä‘Æ°á»£c
		Zend_Db_Table::setDefaultAdapter ( $db );
		// tráº£ vá»� chÃ­nh nÃ³ tuy nhiÃªn nÃ³ cÃ³ thá»ƒ
		// Ä‘Æ°á»£c lÆ°u trá»¯ táº¡i boostrap
		return $db;
	}
	function _initViewHelpers() {
		$this->bootstrap ( 'layout' );
		$layout = $this->getResource ( 'layout' );
		$view = $layout->getView ();
		
		$view->headTitle ()->setSeparator ( ' - ' )->headTitle ( 'Ishali' );
	}
	protected function _initAutoload() {
// 		$modelLoader = new Zend_Application_Module_Autoloader ( array (
// 				'namespace' => '',
// 				'basePath' => APPLICATION_PATH . '/modules/admin' 
// 		) );
		
// 		if (Zend_Auth::getInstance ()->hasIdentity ()) {
// 			Zend_Registry::set ( 'role', Zend_Auth::getInstance ()->getStorage ()->read ()->ROLE_ID );
// 		} else {
// 			Zend_Registry::set ( 'role', 'guests' );
// 		}
		
// 		$this->_acl = new Model_AdminAcl ();
// 		$this->_auth = Zend_Auth::getInstance ();
		
// 		$fc = Zend_Controller_Front::getInstance ();
// 		$fc->registerPlugin ( new Plugin_AccessCheck ( $this->_acl ) );
// 		return $modelLoader;
	}
	protected function _initRoutes() {
		$front = $this->getResource ( 'frontcontroller' );
		$router = $front->getRouter ();
		$config = new Zend_Config_Xml ( APPLICATION_PATH . '/configs/routes.xml' );
		$router->addConfig ( $config->routes );
	}
}

